package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import db.DBConnecter;

import entity.Admin;

import entity.Customer;
import flex.messaging.io.ArrayList;

public class AdminDAO {
	private DBConnecter db;
	public AdminDAO() {
		db = new DBConnecter();//initialize a new connection
	}
	
	public Customer getOneAdmin(String userid){//notify this return type, it borrows a customer type
		ResultSet rs;
		String sql = "select * from admin where AdminID = '"+userid+"'";
		Customer admin = new Customer();
		
		try{
			rs = db.query(sql);
			rs.next();//default only one admin returns
			admin.setCst_id(rs.getString("AdminID"));
			admin.setCst_password(rs.getString("AdminPw"));
			rs.close();
			db.close();
			return admin;
			
		}catch(SQLException e){
			e.printStackTrace();
			db.close();
			return admin;
		}
		
	}
	
	public List<Admin> queryAdmins(String adminid){
		ResultSet rs;
		List<Admin> adminList = new ArrayList();
		String sql = "select * from admin where AdminID = '"+adminid+"' ";
		
		try{
			rs = db.query(sql);
			while(rs.next()){
				Admin admin = new Admin();
				admin.setAdminId(rs.getString("AdminID"));
				admin.setAdminPw(rs.getString("AdminPw"));
				adminList.add(admin);
			}
			System.out.println("adminList.size"+adminList.size());
			rs.close();
			db.close();
			return adminList;
			
		}catch(SQLException e){
			e.printStackTrace();
			db.close();
			return adminList;
		}
			
		
	}
}
